package com.gt.qr;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class QRCodeActivity extends Activity implements QrCodeListener, OnClickListener{
	
	private static final String TAG="QRCodeActivity";
    
	private QrCodeCameraView qrCodeView=null;
	private View framingView=null;
	private ImageView btnLastImage=null;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.qrcode);
        
        QrCodeCameraView.init(this);
        qrCodeView=(QrCodeCameraView)super.findViewById(R.id.qrCodeCv);
        framingView=super.findViewById(R.id.framing_area);
        btnLastImage=(ImageView)super.findViewById(R.id.last_image);
        qrCodeView.setFramingView(framingView);
        qrCodeView.setQrCodeListener(this);
        btnLastImage.setOnClickListener(this);
    }

	@Override
	protected void onPause() {
		qrCodeView.onPause();
		super.onPause();
	}

	@Override
	protected void onResume() {
		qrCodeView.onResume();
		super.onResume();
	}

	@Override
	protected void onDestroy() {
		qrCodeView.onDestroy();
		super.onDestroy();
	}

	@Override
	public void onQrCodeCatched(QrCodeCameraView qrCodeView, String content) {
		Log.i(TAG, "onQrCodeCatched>>>content="+content);
		Toast.makeText(this, "onQrCodeCatched>>>"+content, Toast.LENGTH_LONG).show();
	}

	@Override
	public void onClick(View view) {
		int viewId=view.getId();
		if(viewId==R.id.last_image){
			
			Bitmap bitmap=qrCodeView.getLastImage();
			if(bitmap!=null){
				btnLastImage.setImageBitmap(bitmap);
			}
		}
	}
	
	
    
    
}